package com.github.m6d21.sso.common.util;

import com.google.common.collect.ImmutableList;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;

/**
 *<p>
 *
 *</p>
 *
 * @author liuyang
 * @date 2018/12/21 Fri 10:34:00
 * @since 1.0.0
 */
public class HttpFilterHelper {

    private final static ImmutableList<String> STATIC_RESOURCES = ImmutableList.of(
        ".js", ".css", ".ico", ".png", ".jpg", ".jpeg", ".gif", ".bmp");

    private HttpFilterHelper() {
    }

    public static boolean isStaticResource(String url) {
        if (StringUtils.isEmpty(url)) {
            return false;
        }

        for (String fileSuffix : STATIC_RESOURCES) {
            if (url.endsWith(fileSuffix)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isHtmlRequest(HttpServletRequest request) {
        return request != null && request.getHeader("accept")!=null&&request.getHeader("accept").contains("text/html");
    }
}
